package jdbcTest;
/*草稿 分析 */
import java.sql.*;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");

        String url="jdbc:mysql://localhost:3306/demotest01 ?characterEncoding=UTF-8&serverTimezone=GMT%2B8";
        String user="root";
        String pasd="root";
        Connection conn = DriverManager.getConnection(url, user, pasd);//有人偷懒 直接拿分

        String sql="select * from teacher where tno>? and tname like ?";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        preparedStatement.setInt(1,8);
        preparedStatement.setString(2,"%五");
        //动态要在上面写清楚
        ResultSet resultSet = preparedStatement.executeQuery();

        while(resultSet.next()){
            int tno = resultSet.getInt(1);
            String tname = resultSet.getString(2);
            String tsex = resultSet.getString(3);
            Date tbirthday = resultSet.getDate(4);
            System.out.println(tno+","+tname+","+tsex+","+tbirthday);

        }
        resultSet.close();
        preparedStatement.close();
        conn.close();



    }
}
